package com.android.miniskirt.ui;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.android.miniskirt.R;
import com.android.miniskirt.miniApplication;
import com.android.miniskirt.ui.bubble9;

public class miniskirt extends ListActivity {
	   private static final int GALLERY = 0;
	   private static final int MANU01 = 0;
	   private static final int MANU02 = 1;
	   private static final int MANU03 = 2;
	   private static final int MANU04 = 3;
	   private ArrayList<HashMap<String, Object>> mData;
	   private miniApplication mApplication; 
	   @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	    	super.onCreateOptionsMenu(menu);
	    	menu.add(GALLERY, MANU01, Menu.NONE, "濞ｈ濮炴總钘夊几")
	    	.setShortcut('0', 'k').setIcon(R.drawable.icon);
	    	menu.add(GALLERY, MANU02, Menu.NONE, "鐠佸墽鐤")
	    	.setShortcut('1', 's').setIcon(R.drawable.icon);
	    	menu.add(GALLERY, MANU03, Menu.NONE, "2-缁夛拷")
	    	.setShortcut('2', 'u').setIcon(R.drawable.icon);
	    	menu.add(GALLERY, MANU04, Menu.NONE, "3-閸愶拷")
	    	.setShortcut('3', 'n').setIcon(R.drawable.icon);
	    	return true;
	    }
	   @Override
	    public boolean onOptionsItemSelected(MenuItem item) {
	    	switch (item.getGroupId()) {
	    	case GALLERY:
	    		String itemid = Integer.toString(item.getItemId());
	    		String title = item.getTitle().toString();
	    		showAlertDialog("妞ゅ湱娲癐D = " + itemid + "\n" +
	    				"閺嶅洭顣�= " + title);
	    		return true;
	    	}
	    	return super.onOptionsItemSelected(item);
	    }
	    private void showAlertDialog(String message) {
	    	new AlertDialog.Builder(this)
	    	.setTitle("闁瀚ㄩ懣婊冨礋妞")
	    	.setMessage(message)
	    	.setPositiveButton("閸忔娊妫", null)
	    	.show();
	    }
		@Override
 	    public void onCreate(Bundle savedInstanceState) {
 	        super.onCreate(savedInstanceState);
 	        mApplication = (miniApplication) this.getApplication();
 	        mData = mApplication.getContactsData();
 	        MyAdapter adapter = new MyAdapter(this);
 	        setListAdapter(adapter);
 			
 	    }//OnCreate
	
		public void DisplayToast(String str)
		{
			Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
		}
		@Override
		protected void onListItemClick(ListView l, View v, int position, long id) {

			startActivity(new Intent(miniskirt.this, bubble9.class));
		}
		
		public void showInfo(){

			new AlertDialog.Builder(this)

			.setTitle("闁瀚ㄩ悡褏澧")

			.setItems(R.array.items_irdc_dialog,new DialogInterface.OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					if(which == 0)
					{
						DisplayToast("閻╃鍞");
					}else if (which ==1)
					{
						DisplayToast("閹峰秶鍙");
					}else
					{
						DisplayToast("娑擃亙姹夋穱鈩冧紖");
					}
				}
			})
			.show();
		}
		public final class ViewHolder{
 	        public ImageView img;
 	        public TextView title;
 	        public TextView info;
 	        public Button viewBtn;
 	    }
 	     
 	    public class MyAdapter extends BaseAdapter{
	 
 	        private LayoutInflater mInflater;
 	         
 	         
 	        public MyAdapter(Context context){
 	            this.mInflater = LayoutInflater.from(context);
 	        }
 	        @Override
	        public int getCount() {
 	            // TODO Auto-generated method stub
 	            return mData.size();
 	        }
 	 
 	        @Override
 	        public Object getItem(int arg0) {
 	            // TODO Auto-generated method stub
 	            return null;
 	        }
	 
 	        @Override
 	        public long getItemId(int arg0) {
	            // TODO Auto-generated method stub
	            return 0;
 	        }
 	 
 	        @Override
	        public View getView(int position, View convertView, ViewGroup parent) {
	             
 	            ViewHolder holder = null;
 	            if (convertView == null) {
 	                 
 	                holder=new ViewHolder(); 
 	                
	                convertView = mInflater.inflate(R.layout.vlist2, null);
 	                holder.img = (ImageView)convertView.findViewById(R.id.img);
 	                holder.title = (TextView)convertView.findViewById(R.id.title);
 	                holder.info = (TextView)convertView.findViewById(R.id.info);
	                convertView.setTag(holder);
	                 
	            }else {
 	                 
 	                holder = (ViewHolder)convertView.getTag();
 	            }
 	             	             
 	            holder.img.setBackgroundResource((Integer)mData.get(position).get("img"));
 	            holder.title.setText((String)mData.get(position).get("ItemTitle"));
 	            holder.info.setText((String)mData.get(position).get("ItemText"));
 	            holder.img.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
//						DisplayToast("imgimg");  
						showInfo();
					}
				});
 	           
 	            return convertView;
        }//getView
 	         
	 }//MyAdapter
		
}//MiniSkirt

